import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import Layout from '@/layout/component/router-view.vue'

/**
 * title 标题
 * isHide 是否隐藏路由
 * icon 图标
 * isAffix 是否固定头部窗口菜单
 * isKeepActive
 */

// 公共路由
const routerPublics: any = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/index.vue'),
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404.vue'),
  },
  {
    // 此处vue3更新需要使用catchall方法匹配,不然会出现错误:
    // Catch all routes ("*") must now be defined using a param with a custom regexp
    path: '/:catchAll(.*)',
    redirect: '/404',
  },
]

const route: Array<RouteRecordRaw> = [
  {
    path: '/',
    redirect: '/home',
    name: 'Layout',
    component: () => import('../layout/index.vue'),
    children: [
      {
        path: '/home',
        name: 'home',
        component: () => import('@/views/Home/index.vue'),
        meta: {
          title: '首页',
          isHide: false,
          isAffix: true,
          icon: 'HomeFilled',
        },
      },
    ],
  },
]

const routes = route.concat(routerPublics)

const router = createRouter({
  history: createWebHistory(),
  routes,
})

export default router
